package com.hzw.saas.common.util.enums;

import java.util.Objects;

/**
 * 通用数据状态
 *
 * @author zzl
 * @since 02/26/2021
 */
public enum DataStatusEnum {

    FROZEN(100, "冻结"),
    NORMAL(200, "正常"),
    RECYCLED(300, "回收"),
    DELETED(400, "删除"),
    ;
    public static final String API_TEXT = API_TEXT();

    private final Integer code;
    private final String text;

    DataStatusEnum(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    public Integer getCode() {
        return code;
    }

    public String getText() {
        return text;
    }

    public static DataStatusEnum instance(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (DataStatusEnum value : DataStatusEnum.values()) {
            if (Objects.equals(value.getCode(), code)) {
                return value;
            }
        }
        return null;
    }

    private static String API_TEXT() {
        StringBuilder sb = new StringBuilder("");
        for (DataStatusEnum value : DataStatusEnum.values()) {
            if (sb.length() != 0) {
                sb.append(", ");
            }
            sb.append(value.getCode()).append("-").append(value.getText());
        }
        return sb.toString();
    }
}
